Skip to content

Draw results on the image ​

A model answers with numbers: where each object is and what it is. The image nodes of Rosepetal turn those numbers into pictures: the shapes painted on the image, the boxes around the objects, or a separate image of each object. In this guide you paint the biscuits a model found and cut each one out.

What you will learn

  • How to paint the masks of a segmentation model on the image
  • How to cut out each object the model found
  • Which node draws boxes, points and lines

Before you start

You need a flow that runs a model, as in Run a trained model on an image. Here it brings images of the «DemoCookies» dataset and runs a segmentation model that finds each biscuit; its predictions are in msg.inference and the image in msg.image.

1. Add rp-add-masks ​

Type rp-add-masks in «filter nodes» and drag the node after the inferencer, then wire them together.

Add rp-add-masks

2. Tell it where the image and the masks are ​

Double-click the node. Set «Image» to msg.image, where the image travels, and «Masks Array» to msg.inference, where the model left its predictions. The painted image goes to «Output», msg.payload. «Global Mask Strength» sets how opaque the paint is, and «Class Color Mappings» gives each tag a color of your choice. Tick «Debug» to see the result under the node.

Tell it where the image and the masks are

3. Deploy and look ​

Click «Done», then «Deploy», and press the button of the inject node. Under rp-add-masks you see the image with every biscuit the model found painted in.

Deploy and look

4. Cut out each biscuit ​

Add rp-cropBB and wire the inferencer to it as well: a node can send its output to several nodes. Open it and set «Bounding Boxes» to msg.inference. «Min Confidence» leaves out the objects the model is less sure about than that. Tick «Debug».

Cut out each biscuit

5. Deploy and look again ​

Click «Done», deploy and press the inject node. rp-cropBB sends a list with one image per biscuit in msg.payload, each with its tag, its confidence and where it was. Its preview shows the first one. To handle them one by one, follow it with rp-array-out, in «RP Utils».

Deploy and look again

The drawing nodes ​

NodeWhat it drawsReads
rp-add-masksThe shapes found by a segmentation or anomaly model, painted over the imagepolygons of each prediction
rp-add-bbsA box around each object, with its tag and its confidenceraw_boxes of each prediction
rp-cropBBA separate image of each objectraw_boxes of each prediction
rp-drawPoints and lines at the positions you give it, for marks of your own such as a measurementFixed values or message properties

All of them take positions from 0 to 1, so they work at any image size, and all of them can give their result as raw pixels, the fastest to keep processing, or as a JPEG, PNG or WebP file, ready to save or to show on a panel.

Next steps ​

Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.